--Api 表
/*
select * from SYS_Apis
select * from SYS_ApiM --M  Memo Main Manage

ReturnType
返回类型（类似返回值）
1 execSql 
2 openSql
3 execProc(不带返回结果) 
4 openProc(带返回结果集)
5 getList (使用getList sql 模板)
*/

declare 
  @ApiName varchar(50)='sjjd.edit',
  @ReturnType int =51
--
--
delete from SYS_Apis where ApiName=@ApiName
delete from SYS_ApiM where apiName=@ApiName
insert into SYS_ApiM([apiName],[name],[memo])
select @ApiName,'阶段编辑','阶段编辑'
insert into SYS_Apis(ApiName,paramsLen,params,ReturnType,sqlText)
select @ApiName,0,
null,
@ReturnType,
'if exists(select 1 from [#(dbname)]..sjjd where dgnd=#para(dgnd) and jdmc=#para(jdmc)
#if(jdid) and jdid<>#para(jdid) #end
)
begin
  select 0 as ok,''年度 #(dgnd) 下已存在阶段(#(jdmc))'' as msg
  return
end
#if(jdid)
update [#(dbname)]..sjjd set jdmc=#para(jdmc),editDate=getdate() where jdid=#para(jdid)
#else
insert into [#(dbname)]..sjjd([guid],dgnd,jdmc,pjdmc,isUserDefined,jdlx,editUser,editDate)
values(newid(),#para(dgnd),#para(jdmc),#if(pjdmc)#para(pjdmc)#else null #end,1,''..'',#para(editUser),getdate())
#end
select 1 as ok,''#(dgnd)#(jdmc)'' as jdid
'
